//
//  ViewController.m
//  UIPickView
//
//  Created by dllo on 16/7/25.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "ViewController.h"

@interface ViewController () <UIPickerViewDataSource, UIPickerViewDelegate>
@property (nonatomic, strong) NSArray *array;
@end

@implementation ViewController

//- (NSArray *)arr {
//    if (self) {
//        self.array = arr;
//    }
//    r
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIPickerView *pick = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 400)];
    pick.backgroundColor = [UIColor redColor];
    [self.view addSubview:pick];
    pick.delegate = self;
    pick.dataSource = self;
    self.array = [[NSArray alloc] init];
    self.array = @[@"辽宁", @"大连", @"上海"];
    
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    return self.array.count;
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 5;
}

//- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
//    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
//    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
//    label.text = [_array objectAtIndex:row];
//    [view1 addSubview:label];
//    return view1;
//}

//- (nullable NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component {
//    NSString *str = [_array objectAtIndex:row];
//    NSAttributedString *att = [[NSAttributedString alloc] initWithString:str];
////    att
//
//}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    return [_array objectAtIndex:row];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
